import {onMounted, reactive, ref,} from 'vue';
import { querySfCtaIPag,} from '@/api/url/erp/baseMessage';
import router from "@/router";

export default function importConfig() {
  const base = reactive<any>({
    emptyCheckForm:{},
    checkForm: {
      single:'',
      odd:'',
      ph:'',
      pm:'',
      gy:'',
      fs:'',
    },
    data: [],
    pagination:{
      current:1,
      size:10,
      total:0,
    },
    visible: false, //遮罩层显示
    delVisible: false, //删除用户遮罩层
    loadingFlag: false,
  });

  //获取表格数据
  const getTable = () => {
    let obj={
      current: base.pagination.current,
      size: base.pagination.size,
    };

    let rel=Object.assign(obj,base.checkForm);

    querySfCtaIPag(rel).then((res: any) => {
      if(res.code === 200){
        base.pagination.total = res.data.total;
        base.data = res.data.data;
      }
    })
  };

  //查询
  const search=()=>{
    base.pagination.current=1;
    getTable();
  };

  // 重置
  const reset = () => {
    base.checkForm=JSON.parse(JSON.stringify(base.emptyCheckForm));
    getTable();
  };

  //派工
  const dispatch=(row)=>{
    localStorage.setItem('workshopDispatchReportingData',JSON.stringify(row));
    router.push('/dispatchingWork');
  };
  //存储查询条件
  const storeCondition=()=>{
    localStorage.setItem('workshopDispatchReportingFormData',JSON.stringify(base.checkForm));
  };

  // 跳到详情页
  const toDetail = (row) => {
    storeCondition();

    router.push({
      path: '/querySfCteModel',
      query: { gx: row.ta003.trim(), odd: row.ta001.trim(), single: row.ta002.trim(), source:2 },
    });
  };

  //判断是否有展开行
  const expandConfig = ref({
    visibleMethod ({ row }) {
      if (row.sonList.length>0) {
        return true;
      }
      return false;
    }
  });

  onMounted(()=>{
    base.emptyCheckForm=JSON.parse(JSON.stringify(base.checkForm));
    let relt=JSON.parse(localStorage.getItem('workshopDispatchReportingFormData'));
    if(relt){
      base.checkForm=relt;
    }
    getTable();
  });

  return {
    base,
    getTable,
    reset,
    toDetail,
    dispatch,
    search,
    expandConfig,
  };
}
